package com.aididi;

import com.aididi.factory.RequestTimeGatewayFilterFactory;
import com.aididi.filters.MyRequestGatewayFilter;
import com.aididi.filters.TokenGlobalFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.CrossOrigin;

@SpringBootApplication
@EnableDiscoveryClient
@CrossOrigin
public class GatewayFilterApplication {
	private static final String httpUri = "http://httpbin.org:80";

	public static void main(String[] args) {
		SpringApplication.run(GatewayFilterApplication.class, args);
	}


	/**
	 * 将自定义gateway filter注入到spring ioc容器中
	 * 测试以“customer”开头的请求的请求时间
	 *  通过  curl localhost:8081/customer/123  进行测试
	 * @param builder
	 * @return
	 */
	/*@Bean
	public RouteLocator customerRouteLocator(RouteLocatorBuilder builder){
		return builder.routes()
				.route(p -> p.path("/customer/**")
				.filters(f -> f.filter(new MyRequestGatewayFilter())
				.addRequestHeader("jwttoken","oxz21x1994"))
				.uri(httpUri)
				.order(0)
				.id("customer_filter_router"))
				.build();
	}


	*//**
	 * 将自定义的 gateway filters factory注入为bean
	 * @return
	 *//*
	@Bean
	public RequestTimeGatewayFilterFactory requestTimeGatewayFilterFactory(){
		return new RequestTimeGatewayFilterFactory();
	}


	*//**
	 * 将自定义Global Filter注入到spring ioc容器中
	 * @return
	 *//*
	@Bean
	public TokenGlobalFilter tokenGlobalFilter(){
		return new TokenGlobalFilter();
	}
*/
}
